//
//  GMRegisterDataController.m
//  GuardMan
//
//  Created by steven on 2016/12/28.
//  Copyright © 2016年 steven. All rights reserved.
//

#import "GMRegisterDataController.h"

@implementation GMRegisterDataController

// Get auth code
- (void)getAuthCodeWithParams:(NSDictionary *)params callback:(GMCompletionCallback)callback {
    [self requestWithType:POST url:ACTION_GET_CODE params:params success:^(id object) {
        callback(nil);
    } failure:^(NSInteger statusCode, NSString *message) {
        NSString *errorString = nil;
        switch (statusCode) {
            case 404:
                errorString = @"请求格式出错";
                break;
            case 406:
                errorString = @"请求被拒绝";
                break;
            case 500:
                errorString = @"获取验证码失败";
                break;
            case SERVER_NETWORK_OFF:
                errorString = @"服务器错误";
                break;
            case USER_NETWORK_OFF:
                errorString = @"请检查手机网络";
                break;
            default:
                errorString = UNKOWN_ERROR;
                break;
        }
        
        callback(message ? message : errorString);
    }];
}

// Check auth code
- (void)checkAuthCodeWithParams:(NSDictionary *)params callback:(GMCompletionCallback)callback {
    [self requestWithType:POST url:ACTION_AUTH_CODE params:params success:^(id object) {
        callback(nil);
    } failure:^(NSInteger statusCode, NSString *message) {
        NSString *errorString = nil;
        switch (statusCode) {
            case 500:
                errorString = @"验证失败";
                break;
            case SERVER_NETWORK_OFF:
                errorString = @"服务器错误";
                break;
            case USER_NETWORK_OFF:
                errorString = @"请检查手机网络";
                break;
            default:
                errorString = UNKOWN_ERROR;
                break;
        }
        callback(message ? message : errorString);
    }];
}
@end
